package com.lanou.sfu.songforu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.sfu.songforu.R;
import com.lanou.sfu.songforu.datas.SingerContentEntity;

import java.util.List;

/**
 * Created by quyan on 15/10/29.
 */
public class SingerContentAdapter extends BaseAdapter {
    private List<SingerContentEntity.DataEntity> datas;
    private Context context;

    public SingerContentAdapter(Context context,List<SingerContentEntity.DataEntity> dataEntities) {
        this.context = context;
        this.datas = dataEntities;
    }

    @Override
    public int getCount() {
        return datas != null && datas.size() > 0 ? datas.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.singer_list_content,null);
            holder = new ViewHolder();
            holder.songFaviorNum = (TextView) convertView.findViewById(R.id.song_fivort_num);
            holder.songListTime = (TextView) convertView.findViewById(R.id.song_list_time);
            holder.songTitle = (TextView) convertView.findViewById(R.id.song_title);
            holder.songSinger = (TextView) convertView.findViewById(R.id.song_singer);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        SingerContentEntity.DataEntity entity = (SingerContentEntity.DataEntity) getItem(position);
        holder.songSinger.setText(entity.getSingerName());
        holder.songFaviorNum.setText(entity.getFavorites());
        holder.songTitle.setText(entity.getName());
        holder.songListTime.setText(position + 1 +"");
        return convertView;
    }

    public class ViewHolder{
        private TextView songListTime;
        private TextView songTitle;
        private TextView songSinger;
        private ImageView heart;
        private TextView songFaviorNum;
    }
}
